package com.jrx.anytxn.accounting.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jrx.anytxn.accounting.dto.GlInterfaceExcpReportRes;
import com.jrx.anytxn.accounting.entity.TlGlInterfaceInfoExcpReport;
import com.jrx.anytxn.accounting.mapper.ext.ExtTlGlInterfaceInfoExcpReportMapper;
import com.jrx.anytxn.accounting.service.IGlInterfaceExcpReportService;
import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.param.constant.Constant;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName GlInterfaceExcpReportServiceImpl
 * @Description: 总账流水例外报告表service实现层
 * @Author yf
 * @Date 2019/9/23 0023
 * @Version V1.0
 **/
@Service
public class GlInterfaceExcpReportServiceImpl implements IGlInterfaceExcpReportService {

    @Resource
    private ExtTlGlInterfaceInfoExcpReportMapper extTlGlInterfaceInfoExcpReportMapper;


    private static final Logger logger = LoggerFactory.getLogger(VoucherExcpReportServiceImpl.class);


    @Override
    public TxnPage<GlInterfaceExcpReportRes> getPage(Integer pageNum, Integer pageSize, String tenantId,String customerId,String loanId) throws TxnBizException {
        Page<GlInterfaceExcpReportRes> page = PageHelper.startPage(pageNum, pageSize);
        List<TlGlInterfaceInfoExcpReport> tlGlInterfaceInfoExcpReportList = extTlGlInterfaceInfoExcpReportMapper.selectAllByPageAndTenId(tenantId,customerId,loanId);
        if (tlGlInterfaceInfoExcpReportList.isEmpty()) {
            logger.error("查询的总账流水例外报表列表为空");
            throw new TxnBizException(TxnRespCode.SUCCESS.getCode(), "总账流水例外报表没有数据");
        }
        List<GlInterfaceExcpReportRes> res = BeanMapping.copyList(tlGlInterfaceInfoExcpReportList, GlInterfaceExcpReportRes.class);
        return new TxnPage<>(pageNum, pageSize, page.getTotal(), res);
    }

    @Override
    public GlInterfaceExcpReportRes getModalByIdAndTenIdAndCusId(Long id,String tenantId,String customerId) throws TxnBizException {
        if (id == null&&StringUtils.isBlank(tenantId)&&StringUtils.isBlank(customerId)) {
            logger.error("总账流水例外报表主键ID或租户ID或客户ID为空");
            throw new TxnBizException(TxnRespCode.NOT_EMPTY.getMsg());
        }
        TlGlInterfaceInfoExcpReport tlGlInterfaceInfoExcpReport = extTlGlInterfaceInfoExcpReportMapper.selectByIdAndTenIdAndCusId(id,tenantId,customerId);
        if (null == tlGlInterfaceInfoExcpReport) {
            logger.error("根据主键[{}]查询的总账流水例外报表集合为空", id);
            throw new TxnBizException(TxnRespCode.NO_DATA.getMsg());
        }
        return BeanMapping.copy(tlGlInterfaceInfoExcpReport, GlInterfaceExcpReportRes.class);
    }
}
